'use strict'

let Ids = require('./model').Ids
let serverConfig = require('../../config/serverConfig').serverConfig
let serverId = serverConfig.serverId

Ids.find({
    _id: serverId
}, function(err, res) {
    if (!err) {
        if (!res || res.length === 0) {
            let ids = new Ids({
                _id: serverId,
                playerId: 1,
                serverId: 1,
                mailId: 1,
                tradeId: 1,
            })
            ids.save()
        }
        if (res.length === 1) {
            let con = {
                playerId: res[0].playerId || 1,
                serverId: res[0].serverId || 1,
                mailId: res[0].mailId || 1,
                tradeId: res[0].tradeId || 1,
                userId: res[0].userId || 1,
            }
            Ids.update({
                _id: serverId
            }, con, {}, function(err) {
                if (err) {
                    Log('ids数据出错')
                    throw new Error('ids数据出错')
                }
            })
        }
    }
})
